//
// See the file COPYING for redistribution information.
//

#ifndef __NAIPAX_LINKEXTOR_HPP__
#define __NAIPAX_LINKEXTOR_HPP__

#include <vector>
#include <string>

namespace Naipax {
    /** This class is used to extract links from HTML/XML documents
     *
     * Currently, pcrecpp is used as the backend extraction engine.
     */
    class LinkExtor {
    public:

        /** Constructor
         *
         * @param MaxLinks The maximum number of links to be extracted.
         * @param MaxPathDepth The maximum depth of path that is allowed
         */
        LinkExtor(uint32_t MaxLinks = 1024, uint32_t MaxPathDepth = 5);

        /// Destructor
        ~LinkExtor();

        /** Extract links
         *
         * Duplicate links are ignored. Each link in rUrls is
         * distinct. Every time this method is called, it clears rUrls
         * before trying to extract links. This method assumes rHtml
         * is encoded in UTF-8. No check on encoding is performed.
         *
         * This method does not throw any exception.
         *
         * @param rHtml HTML document
         * @param rUrls Extracted URLs
         */
        void Extract(const std::string &rHtml,
                     std::vector<std::string> &rUrls);

        /// Getter/Setter of _mMaxLinks
        uint32_t& MaxLinks() { 
            return _mMaxLinks;
        }

        /// Getter/Setter of _mMaxLinks
        uint32_t& MaxPathDepth() { 
            return _mMaxPathDepth;
        }

        /// Getter/Setter of _mBaseUrl
        std::string& BaseUrl() { 
            return _mBaseUrl;
        }

        /** Getter/Setter of _mDiscardPattern
         *
         * The pattern will be compiled into a PCRECPP object.
         */
        std::string& DiscardPattern() { 
            return _mDiscardPattern;
        }

    private:
        uint32_t _mMaxLinks;
        uint32_t _mMaxPathDepth;
        std::string _mBaseUrl;
        std::string _mDiscardPattern;
    };
};

#endif // __NAIPAX_LINKEXTOR_HPP__
